package leet;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fance
 * @date 18-5-10 上午7:00
 */
public class MathSum {

    /**
     * 728. 自除数
     * @param left
     * @param right
     * @return
     */
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> res = new ArrayList<>();
        for (int i = left; i <= right; i++) {
            if (isSelfDividingNumber(i)) {
                res.add(i);
            }
        }
        return res;
    }
    private boolean isSelfDividingNumber(int n) {
        int tmp = n;
        boolean res = true;
        while (tmp > 0) {
            int cur = tmp % 10;
            if (cur == 0 || n % cur != 0) {
                return false;
            }
            tmp /= 10;
        }
        return res;
    }

    @Test
    public void test() {
        String J = "aA", S = "aAAbbbb";
        List<Integer> res = selfDividingNumbers(1,22);
        for (Integer n : res) {
            System.out.print(n + " ");
        }
    }

}
